import React from 'react'
import { Result,List,WhiteSpace,Button,Modal,WingBlank } from 'antd-mobile';
import { connect } from 'react-redux';
import cookies  from 'browser-cookies'
import {logoutSubmit} from '../../redux/user.redux'
import { Redirect } from 'react-router-dom';
@connect(
    state=>state.user,
    {logoutSubmit}
)
class User extends React.Component{
    constructor(props){
        super(props)
        this.logout=this.logout.bind(this)
    }
    logout(){
        const alert = Modal.alert
        alert('退出登录','确认退出吗？',[
            {text:'取消',onPress:()=>console.log('取消')},
            {text:'确认',onPress:()=>{
                cookies.erase('userid')
                // window.location.href =window.location.href  
                this.props.logoutSubmit()
            }},
        ])
    }
    render(){
        const props =this.props
        const Item = List.Item 
        const Brief = Item.Brief
        return props.user?(
           <div>
               <Result 
                  img={<img src={require('../img/'+props.avatar+'.png')} style={{width:50}} alt=''/>}
                  title={props.user}
                  message={props.type=='boss'?props.company:null}
               />
               <List renderHeader={()=>'简介'}>
                  <Item
                      multipleLine
                  >
                        {props.title}
                        {props.desc.split('\n').map(v=><Brief key={v}>{v}</Brief>)}
                        {props.money?<Brief>薪资：{props.money}</Brief>:null}
                  </Item>                
               </List>
               <WhiteSpace></WhiteSpace>
               <WingBlank>
                    <Button type="warning" onClick={this.logout} style={{zIndex:'1'}}>退出登录</Button> 
               </WingBlank>
           </div>
        ):<Redirect to={props.redirectTo}></Redirect>
    }
}

export default User